<div class="wide form">
    <?php echo CHtml::beginForm(); ?>
    <fieldset id="packing_list" class="ui-widget section">
        <legend class="ui-widget-header ui-corner-all">Shipment information</legend>
        <p class="note">Fields with <span class="required">*</span> are required.</p>
        <?php echo CHtml::errorSummary($model); ?>
        <div id="errorsummary"></div>
        <div class="row">
            <?php echo CHtml::activeLabelEx($model,'date'); ?>
            <?php $this->widget('zii.widgets.jui.CJuiDatePicker',
                array(
                'model'=>$model,
                'attribute'=>"date",
                'htmlOptions'=>array('size'=>60,'value'=>(!empty($model->date))?(is_numeric($model->date))?date('d/m/Y',$model->date):$model->date:date('d/m/Y')),
                'options'=>array('dateFormat'=>'dd/mm/yy'),
                )
            );
            ?>
            <?php echo CHtml::error($model,'date'); ?>
        </div>
        <div class="row ui-widget">
            <?php echo CHtml::activeLabelEx($model,'shipping_id'); ?>
            <?php
                $contacturl = CHtml::normalizeUrl(array('company/create'));
                $refurl = CHtml::normalizeUrl(array('packing_list/companycreate/for/company'));
                $this->widget('zii.widgets.jui.CJuiAutoComplete',
                array(
                    'model'=>$model,
                    'attribute'=>'shipping_name',
                    'sourceUrl'=>array('company/autocompletename'),
                    'options'=>array('minLength'=>3,
                                    'select'=>"js:function(event,ui){ $('input#packing_list_shipping_id').val(ui.item.id);
                                                                        if(ui.item.id<=0){
                                                                            $.ajax({data:{ref:'$refurl'},
                                                                                    url:'$contacturl',
                                                                                    success:function(data,status){ closeWaitingDialog(); $('#extra_content').html(data).show();$('#content').hide();},
                                                                                    beforeSend:function(){waitingDialog({message:'Sending request....'});},
                                                                                    global:false })}}",
                    ),
                    'htmlOptions'=>array('size'=>60)
                )); ?>
            <?php echo CHtml::activeHiddenField($model,'shipping_id'); ?>
            <?php echo CHtml::error($model,'shipping_id'); ?>
        </div>
        <div class="row">
            <?php echo CHtml::activeLabelEx($model,'pod'); ?>
            <?php
                $contacturl = CHtml::normalizeUrl(array('company/create'));
                $refurl = CHtml::normalizeUrl(array('packing_list/companycreate/for/shipping'));
                $this->widget('zii.widgets.jui.CJuiAutoComplete',
                array(
                    'model'=>$model,
                    'attribute'=>'pod_name',
                    'sourceUrl'=>array('company/autocompletename'),
                    'options'=>array('minLength'=>3,
                                    'select'=>"js:function(event,ui){ $('input#packing_list_pod').val(ui.item.id);if(ui.item.id<=0){ $.ajax({data:{ref:'$refurl'},url:'$contacturl',success:function(data,status){ closeWaitingDialog(); $('#extra_content').html(data).show();$('#content').hide();},beforeSend:function(){waitingDialog({message:'Sending request....'});},global:false })}}"
                    ),
                    'htmlOptions'=>array('size'=>60)
                )); ?>
            <?php echo CHtml::activeHiddenField($model,'pod'); ?>
            <?php echo CHtml::error($model,'pod'); ?>
        </div>
        <div class="row">
            <?php echo CHtml::activeLabelEx($model,'subject'); ?>
            <?php echo CHtml::activeTextField($model,'subject',array('size'=>60,'maxlength'=>125)); ?>
            <?php echo CHtml::error($model,'subject'); ?>
        </div>
    </fieldset>
    <fieldset id="package_collections" class="ui-widget section">
        <legend class="ui-widget-header ui-corner-all">Packing List Packages</legend>
        <?php 
            foreach($model->packages as $i=>$item){
                if($i>0)
                    echo "<hr />";
                $this->renderPartial('_packingform',array('item'=>$item,'i'=>$i));
            }
        ?>
    </fieldset>
    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', ''); ?>
    </div>

    <?php echo CHtml::endForm(); ?>

</div><!-- form -->